﻿using System;
using System.Xml;

namespace Whois.API
{
    public class WhoisApiException : Exception
    {
        readonly string messageDetailed;
        /// <summary>
        /// Detail of message returned from API (if available), otherwise returns Message
        /// </summary>
        public string MessageDetailed
        {
            get { return messageDetailed; }
        }

        public WhoisApiException()
        {
        }
        public WhoisApiException(string message)
            : base(message)
        {
        }
        public WhoisApiException(string message, Exception inner)
            : base(message, inner)
        {
        }
        public WhoisApiException(XmlNode errorMessage, Exception inner)
            : base(errorMessage==null ? "" : errorMessage.OuterXml, inner)
        {
            if (errorMessage != null)
            {
                var msgNode = errorMessage.SelectSingleNode("//msg");
                messageDetailed = msgNode == null ? errorMessage.OuterXml : msgNode.InnerText;
            }
        }

    }
}
